<script>
/**
	 * vuex管理登陆状态，具体可以参考官方登陆模板示例
	 */
	import httpPath from '@/static/js/path.js';
	import {
		mapMutations
	} from 'vuex';
	export default {
		methods: {
			...mapMutations(['login'])
		},
		onLaunch: function() {
            //更新登陆状态
            uni.getStorage({
                key: 'userInfo',
                success: (res) => {
                    this.login(res.data);	
                }
            });	
			setTimeout(function() {
				// 检测升级
				uni.request({
					url: httpPath.filePath+'/api.php/index/renew/index', //检查更新的服务器地址
					data: {
					},
					success: (res) => {
						console.log(res)
						if (res.data.code == "200") {
					        let verion=res.data.result.upEdition;
							let cur_version=plus.runtime.version;
							if(verion!=cur_version){
								let openUrl = plus.os.name === 'iOS' ? res.data.result.upIosUrl : res.data.result.upAndroidUrl;
								// 提醒用户更新
								uni.showModal({
									title: '更新提示',
									content: "您好，发现新版本，是否需要更新？",
									success: (showResult) => {
										if (showResult.confirm) {
											plus.runtime.openURL(openUrl);
										}	
									}
								})
							}
						}
					}
				})
			}, 5000);	
		},
		onShow: function() {
			console.log('App Show')
			/* 5+  push 消息推送 ps:使用:H5+的方式监听，实现推送*/
			plus.push.addEventListener("click", function(msg) {  
				console.log("click:"+JSON.stringify(msg));  
				console.log(msg.payload);  
				console.log(JSON.stringify(msg));  
				//这里可以写跳转业务代码
				uni.redirectTo({
					url:'/pages/myself/messagelist'
				})
			}, false);  
					// 监听在线消息事件    
			plus.push.addEventListener("receive", function(msg) {  
				// plus.ui.alert(2);  
					//这里可以写跳转业务代码
					uni.redirectTo({
						url:'/pages/myself/messagelist'
					})
				console.log("recevice:"+JSON.stringify(msg))  
			}, false);  
		},
		onHide: function() {
			console.log('App Hide')
		},
	}
</script>
<style>
	/*每个页面公共css */
	/* @import "/colorui/main.css"; */
	@import "/colorui/icon.css";
	@import "/common/app.css";
	@import "/static/iconfont/font.scss";
	@import "/static/css/style.css";
</style>
